package com.yoyo.itravel.dao;

import com.yoyo.itravel.bean.SightCompany;
import com.yoyo.itravel.constants.BaseSqlProviderConstant;
import com.yoyo.itravel.sql_provider.BaseSqlProvider;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.List;

/**
 * @Description 景点公司操作持久层接口
 * @Author HZX
 * @Version 1.0
 * @Date 2020/6/26 11:29
 */
@Repository
public interface ISightCompanyDao {

    /**
     * @Description 插入景点公司
     *
     * @param sightCompany
     * @return int
     */
    @InsertProvider(type = BaseSqlProvider.class, method = BaseSqlProviderConstant.INSERT)
    int insert(SightCompany sightCompany) throws SQLException;

    /**
     * @Description 通过景点公司id删除景点公司
     *
     * @param sightCompany
     * @return int
     */
    @DeleteProvider(type = BaseSqlProvider.class, method = BaseSqlProviderConstant.DELETE_BY_ID)
    int deleteById(SightCompany sightCompany) throws SQLException;

    /**
     * @Description 通过景点公司属性查询景点公司
     *
     * @param sightCompany
     * @return int
     */
    @SelectProvider(type = BaseSqlProvider.class, method = BaseSqlProviderConstant.SELETE)
    List<SightCompany> select(SightCompany sightCompany) throws SQLException;

    /**
     * @Description 通过景点公司id查找公司
     *
     * @Param sightCompanyId
     * @Return com.yoyo.itravel.bean.SightCompany
     */
    @Select("select * from tb_sight_company where sightCompanyId=#{sightCompanyId}")
    SightCompany selectById(String sightCompanyId) throws SQLException;
    /**
     * @Description 通过景点公司id修改景点公司信息
     *
     * @param sightCompany
     * @return int
     */
    @UpdateProvider(type = BaseSqlProvider.class, method = BaseSqlProviderConstant.UPDATE_BY_ID)
    int updateById(SightCompany sightCompany) throws SQLException;

    /**
     * @Description 通过门票具体类型id查找景点公司支付宝UID
     *
     * @param detailTypeId
     * @return java.lang.String
     */
    @Select("SELECT alipayUID FROM tb_sight_company WHERE sightCompanyId IN (" +
            "SELECT sightCompanyId FROM tb_sight WHERE sightId IN (" +
            "SELECT sightId FROM tb_ticket_type WHERE ticketTypeId IN (" +
            "SELECT ticketTypeId FROM tb_ticket_detail_type WHERE detailTypeId=#{detailTypeId})));")
    String selectAlipayUIDByDetailTypeId(String detailTypeId) throws SQLException;
}
